package rexsee.barcode;
import rexsee.barcode.BarcodeCaptureDialog;
import android.graphics.Point;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Message;

public class CameraPreviewCallback implements Camera.PreviewCallback {

	private final BarcodeCaptureDialog mDialog;
	private Handler previewHandler;
	private int previewMessage;

	public CameraPreviewCallback(BarcodeCaptureDialog dialog) {
		mDialog = dialog;
	}
	public void setHandler(Handler previewHandler, int previewMessage) {
		this.previewHandler = previewHandler;
		this.previewMessage = previewMessage;
	}
	@Override
	public void onPreviewFrame(byte[] data, Camera camera) {
		Point cameraResolution = mDialog.mCameraResolution;
		if (!mDialog.mUseOneShotPreviewCallback) {
			camera.setPreviewCallback(null);
		}
		if (previewHandler != null) {
			Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y, data);
			message.sendToTarget();
			previewHandler = null;
		}
	}

}
